package com.yuchao.springboot.config;


import com.yuchao.springboot.configuration.ConfigurationA;
import com.yuchao.springboot.configuration.ConfigurationB;
import com.yuchao.springboot.factory.Factory;
import com.yuchao.springboot.template.Template;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @description:  测试Import的注入顺序，是根据顺序来的
 *
 * 用来理解springboot自动配置redis   spring-boot-starter-data-redis
 *
 * ConfigurationA -> LettuceConnectionConfiguration
 * ConfigurationB -> JedisConnectionConfiguration
 *
 * Factory ->  RedisConnectionFactory
 * FactoryA -> LettuceConnectionFactory
 * FactoryB -> JedisConnectionFactory
 *
 * template -> RedisTemplate
 *
 * @author: xingyuchao
 * @date: 2019-11-21
 */
@Configuration
@Import({ConfigurationA.class,ConfigurationB.class})
public class TestConfig {

	@Bean
	@ConditionalOnMissingBean(name = "template")
	public Template template(Factory factory) {
		Template template = new Template();
		template.setFactory(factory);
		return template;
	}
}
